package com.example.dreamlist2.friend;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextPaint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import com.baidu.location.LocationClient;
import com.baidu.mapapi.map.BaiduMap;
import com.bumptech.glide.Glide;
import com.example.dreamlist2.goal.HabitCompleteItem;

import java.util.List;

import com.example.dreamlist2.R;

public class HabitListAdapter extends RecyclerView.Adapter<HabitListAdapter.ViewHolder>{
    private Context mContext ;

    private List<HabitCompleteItem> recordList ;

    private AdapterView.OnItemClickListener mOnItemClickListener;

    static class ViewHolder extends RecyclerView.ViewHolder{

        CardView cardView ;
        TextView record_content;
        TextView record_times;
        private TextView get_gps;
        TextView record_list_cont;
        ImageView photo_add;
        TextView record_date;
        TextView record_pos;
        TextView record_feel;

        public ViewHolder(@NonNull View itemView, AdapterView.OnItemClickListener mOnItemClickListener) {
            super(itemView);
            cardView = (CardView) itemView;
            record_content = (TextView) itemView.findViewById(R.id.record_list_cont);
            record_times = (TextView) itemView.findViewById(R.id.record_list_times);
            get_gps = (TextView) itemView.findViewById(R.id.record_list_text_gps);
            record_list_cont = (TextView) itemView.findViewById(R.id.record_list_cont);
            photo_add = (ImageView) itemView.findViewById(R.id.record_list_img_photo_add);
            record_date = (TextView) itemView.findViewById(R.id.record_list_text_date);
            record_pos = (TextView) itemView.findViewById(R.id.record_list_text_gps);
            record_feel = (TextView) itemView.findViewById(R.id.record_list_cont_feeling);

            record_list_cont.setTextColor(Color.BLACK);
            TextPaint tp = record_list_cont.getPaint();
            tp.setFakeBoldText(true);


        }
    }

    public HabitListAdapter(List<HabitCompleteItem> mRecordList) {

        this.recordList = mRecordList;
    }


    @NonNull
    @Override
    public HabitListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        if (mContext == null){
            mContext = viewGroup.getContext();
        }
        View view = LayoutInflater.from(mContext).inflate(R.layout.record_item,viewGroup,false);

        final ViewHolder holder = new ViewHolder(view, mOnItemClickListener);

        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull HabitListAdapter.ViewHolder viewHolder, int i) {
        HabitCompleteItem record = recordList.get(i);
        viewHolder.record_content.setText(record.getHcont());
        viewHolder.record_times.setText("第"+record.getThis_time()+"次打卡本习惯");
        viewHolder.record_date.setText(record.getDate().getDate());
        viewHolder.record_feel.setText(record.getFeeling());
        viewHolder.record_pos.setText(record.getPos());
        Glide.with(mContext).load(record.getPhotopath()).into(viewHolder.photo_add);
    }

    @Override
    public int getItemCount() {
        return recordList.size();
    }
}
